package com.ding.service.Impl;

import com.ding.dao.Impl.StudentDaoImpl;
import com.ding.dao.StudentDao;
import com.ding.entity.Student;
import com.ding.service.StudentService;
import com.ding.util.Page;

import java.util.List;

public class StudentServiceImpl implements StudentService {
    StudentDao studentDao = new StudentDaoImpl();

    @Override
    public Page<Student> selectPage(Page page, String stuName, Integer classId) {

        int count = studentDao.count(stuName, classId);


        List<Student> studentList = studentDao.selectList(page, stuName, classId);

        page.setTotalCount(count);
        page.setDataList(studentList);


        return page;
    }

    @Override
    public boolean editStu(Student student) {
        int count = -1;
        if (student.getId() != -1) {
            //编辑
            count = studentDao.updateStu(student);
        } else {
            //新增
            count = studentDao.addStu(student);

        }
        return count > 0 ? true : false;
    }

    @Override
    public Student stuDetail(int id) {
        return studentDao.stuDetail(id);
    }

    @Override
    public int delStu(Integer id) {
        return studentDao.delStu(id);
    }
}
